<?php
include_once $_SERVER['DOCUMENT_ROOT']."/class/errorClass.php";
include_once $_SERVER['DOCUMENT_ROOT']."/class/userClass.php";
include_once $_SERVER['DOCUMENT_ROOT']."/class/model.php";

class controller {

private $error;
private $result;
private $model;
private $user; //ссылка на объект

    function __construct($data) {
        session_start();        
        $this->model = new model();
        $this->result = false;
        $this->error = new error();
        
        if (!empty($data)) {
            switch ($data['act']) {
                case "checkUser": 
                    if ($this->model->user->checkUserLogin($data['email'],$data['passwd']) != 0) {
                        echo $this->model->user->id;
                    }
                    else echo '0';
                    break;
                case "exitUser":
                    $this->model->user->exitUser();
                    break;
                                   
            default : echo '0';
            }
        }
        else{
            if (!$id = $this->model->user->checkUserAuth()) {
            }

            if ($this->model->dbErr) $this->error->showErrMsg (1);   
            $this->processData();
        }
                
    }
   

    function processData() {
        view::showPage($this->model->user);
      
    }
    
    function logLocal($messa, $messa1 = '') {
        ///echo '<p><font size=2 color=blue>'.$messa."\t".$messa1.'</font></p>';
    }


}
?>
